﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using HYFamilyLibDataManager;
using HYSump.DataDefine;

namespace HYSump
{
	internal class LoadFamily
	{
		public LoadFamily(ExternalCommandData commandData)
		{
			this.m_Revit = commandData;
			string appRootPath = AssistFunc.GetAppRootPath();
			string versionNumber = this.m_Revit.Application.Application.VersionNumber;
			this.m_strFullPath = appRootPath + "\\FamilyLib\\Family\\";
			this.m_strFullPath += versionNumber;
			this.m_strFullPath += "\\Sump\\";
		}

		public bool LoadSumpFamilys()
		{
			try
			{
				Document document = this.m_Revit.Application.ActiveUIDocument.Document;
				IEnumerator<KeyValuePair<string, string>> enumerator = Type2FileInfo.m_DicTypeToPath.GetEnumerator();
				while (enumerator.MoveNext())
				{
					string strFullPath = this.m_strFullPath;
					KeyValuePair<string, string> keyValuePair = enumerator.Current;
					string familyFileName = strFullPath + keyValuePair.Value + ".rfa";
					FamilyUtil.ReloadFamily(document, familyFileName);
				}
				enumerator = Type2FileInfo.m_DicKindToPath.GetEnumerator();
				while (enumerator.MoveNext())
				{
					string strFullPath2 = this.m_strFullPath;
					KeyValuePair<string, string> keyValuePair = enumerator.Current;
					string familyFileName2 = strFullPath2 + keyValuePair.Value + ".rfa";
					FamilyUtil.ReloadFamily(document, familyFileName2);
				}
			}
			catch (Exception)
			{
				MessageBox.Show("族文件加载失败!");
				return false;
			}
			return true;
		}

		private ExternalCommandData m_Revit;

		private string m_strFullPath;
	}
}
